﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoolCode
{
    public class ValidatingMessage : BaseMessage, IValidatingMessage
    {
        private string _message;

        public override string Message
        {
            get
            {
                return _message ?? base.Message;
            }
        }

        public string Code { get; protected set; }

        public string ParamName { get; protected set; }

        public virtual MessageType Type { get; protected set; }

        public object[] ExtraData { get; protected set; }

        public ValidatingMessage()
            : this(MessageType.Error, "", "E0013")
        {
        }

        public ValidatingMessage( string paramName, string code, params  object[] extraData)
            : this(MessageType.Error, paramName,code, extraData )
        {
        }

        public ValidatingMessage(MessageType type, string paramName, string code, params  object[] extraData)
            : base()
        {
            this.Type = type;
            this.Code = code;
            this.ParamName = paramName;
            this.ExtraData = extraData;
        }

        public void Retrieve(string message)
        {
            if (this.ExtraData != null && this.ExtraData.Length > 0)
            {
                _message = string.Format(message, this.ExtraData);
            }
            else
            {
                _message = message;
            }
        }
    }

    public  abstract class BaseMessage
    {
        public virtual string Message { get {return string.Empty ;} }
    }
}
